package com.tim.app.server.api;

import android.content.Intent;
import android.net.Uri;
import android.webkit.JavascriptInterface;

import com.application.library.runtime.event.EventManager;
import com.tim.app.RT;
import com.tim.app.constant.EventTag;
import com.tim.app.server.entry.InputContent;
import com.tim.app.ui.view.LSWebView;


public class APIJSInterface {

    public static final String JS_FUNCTION_NAME = "jasmine";

    private LSWebView webView;

    public APIJSInterface(LSWebView webView) {
        this.webView = webView;
    }

    @JavascriptInterface
    public void telephone(String tel) {
        //用intent启动拨打电话
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tel));
        RT.application.startActivity(intent);
    }

    @JavascriptInterface
    public void ema(String mail) {
        Intent data = new Intent(Intent.ACTION_SENDTO);
        data.setData(Uri.parse("mailto:" + mail));
        RT.application.startActivity(data);
    }

    @JavascriptInterface
    /**
     *
     * @text 输入的纯文本
     *
     * @headImage 头图
     *
     * @context 输入的内容转成HTML的文本
     */
    public void getTextHrefContext(String text, String headImage, String context) {
        InputContent inputContent = new InputContent();
        inputContent.setContent(context);
        inputContent.setText(text);
        inputContent.setHeadImage(headImage);
        EventManager.ins().sendEvent(EventTag.ON_GET_CONTENT, 0, 0, inputContent);
    }

}
